package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup

func getChannel(c chan int) chan<- int {
	return c
}
func setChannel(c chan int, n int) <-chan int {
	c <- n
	return c
}
func main() {

	wg.Add(2)
	go func() {
		defer wg.Done()
		var c1 = make(chan int, 10)
		temp := setChannel(c1, 10)     // 返回只读通道
		fmt.Printf("temp: %T\n", temp) // temp: <-chan int
		x, _ := <-c1
		fmt.Printf("x:%d\n", x) // intx:10

		// 尝试写入 err:cannot send to receive-only channel temp
		// temp <- 100 //
	}()
	var c2 = make(chan int, 5)
	go func() {
		defer wg.Done()
		c2 <- 11
		temp := getChannel(c2) // 返回只写通道
		temp <- 100
		// 尝试读取 err:cannot receive from send-only channel temp
		// n := <-temp //
	}()
	num := <-c2
	fmt.Printf("num: %v\n", num) // num: 11
	num2 := <-c2
	fmt.Printf("num2: %v\n", num2) // num2: 100
	wg.Wait()
}
